﻿namespace Web.Control.WWW.Teach
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections;

    using Lx.Web.Common.ControlsUI;    
    using System.Collections.Generic;
    using System.Reflection;
    /// <summary>
    /// SearchPartner 的摘要说明
    /// </summary>
    public class TSearch : BaseControl
    {
        /// <summary>
        /// 当前会员号
        /// </summary>
        string memberno = "";
        /// <summary>
        /// 教师类型1：职业教师、2：辅导教师、3：职业教师和辅导教师
        /// </summary>
        protected string TType = "3";
        /// <summary>
        /// 教学语言
        /// </summary>
        protected string TL = "";
        /// <summary>
        /// 使用语言
        /// </summary>
        protected string BL = "";
        /// <summary>
        /// 国籍
        /// </summary>
        protected string Nationality = "";
        /// <summary>
        /// 最大时薪
        /// </summary>
        protected string MaxPrice = "";
        /// <summary>
        /// 最小时薪
        /// </summary>
        protected string MinPrice = "";        
        /// <summary>
        /// 是否只显示母语1为TL的会员0否、1是
        /// </summary>
        protected string IsNativeBL = "0";
        /// <summary>
        /// 是否只显示免费教课的老师0否、1是
        /// </summary>
        protected string IsFree = "0";
        /// <summary>
        /// 排序 1：LastLogin desc、2：StarRate desc、3：Sessions desc、4：Price asc
        /// </summary>
        protected string SortBy = "1";        
        /// <summary>
        /// 详细列表大小
        /// </summary>
        protected Literal litCount;        
        protected Repeater rptUserList;
        /// <summary>
        /// 绑定大图标头像列表
        /// </summary>
        protected Repeater rptBigUserList;
        protected Repeater rptPopular;
        protected int RecordCount = 0;
        protected int PageIndex = 1;
        protected int psize = 20;
        /// <summary>
        /// 根据 昵称名或会员email或会员号搜索
        /// </summary>
        protected string Name_F = "";

        protected string C0003 = "";
        protected string C0118 = "";
        protected string C0005 = "";
        protected string C0116 = "";

        protected override void OnLoad(EventArgs e)
        {
            C0003 = GetText("C0003");
            C0118 = GetText("C0118");
            C0005 = GetText("C0005");
            C0116 = GetText("C0116");

            ArrayList arrList = null;
            memberno = HttpContext.Current.User.Identity.Name;
            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["p"] == "L")
                {
                    PageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out PageIndex);
                }
            }
            if (!string.IsNullOrEmpty(Request["sort"]))
            {
                SortBy = Request["sort"];
            }
            if (!string.IsNullOrEmpty(Request["name"]))
            {
                Name_F = Request["name"];
            }
            else
            {
                if (!string.IsNullOrEmpty(Request["ttype"]))
                {
                    TType = Request["ttype"];
                }
                if (!string.IsNullOrEmpty(Request["tl"]))
                {
                    TL = Request["tl"];
                }
                if (!string.IsNullOrEmpty(Request["bl"]))
                {
                    BL = Request["bl"];
                }
                if (!string.IsNullOrEmpty(Request["nation"]))
                {
                    Nationality = Request["nation"];
                }
                if (!string.IsNullOrEmpty(Request["max"]))
                {
                    MaxPrice = Request["max"];
                }
                if (!string.IsNullOrEmpty(Request["min"]))
                {
                    MinPrice = Request["min"];
                }
                if (!string.IsNullOrEmpty(Request["free"]))
                {
                    IsFree = Request["free"];
                }
                if (!string.IsNullOrEmpty(Request["istl"]))
                {
                    IsNativeBL = Request["istl"];
                }
            }

            if (litCount != null) int.TryParse(litCount.Text, out psize);

            if (Name_F != "")
                arrList = BLF.WWW_User.Teach.Teach.GetFindTeacher_MN(Name_F, memberno, SortBy, PageIndex, psize);
            else
            {
                decimal maP;
                decimal miP;
                decimal.TryParse(MaxPrice, out maP);
                decimal.TryParse(MinPrice, out miP);
                if (maP == 0)
                {
                    maP = 999999;
                }
                arrList = BLF.WWW_User.Teach.Teach.GetFindTeacher(memberno, TType == "3" ? "" : TType, TL, BL, Nationality, maP, miP, IsFree == "1" ? true : false, IsNativeBL == "1" ? true : false, SortBy, PageIndex, psize);
            }
            if (arrList != null)
            {
                RecordCount = (int)arrList[0];
                int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)psize));
                if (PageIndex > pCount) PageIndex = pCount;

                if (rptUserList != null)
                {
                    rptUserList.DataSource = arrList[1];
                    rptUserList.DataBind();
                }
                if (rptPopular != null)
                {
                    List<BLF.LanguageObj> lanObjList = new List<BLF.LanguageObj>();
                    lanObjList.AddRange(BLF.StaticData.GetPopLanguageList);
                    rptPopular.DataSource = lanObjList;
                    rptPopular.DataBind();
                }
            }
            base.OnLoad(e);
        }       
    }
}
